package com.base.test.mutual.dto;

import com.base.commons.tools.exception.ErrorCode;
import com.base.commons.tools.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * wms返回转成ods返回结果
 * @author wangwenji
 * @param <T>
 */
@Data
@ApiModel(value = "WMS公共返回值")
public class WmsResultRespData<T> implements Serializable{

    private static final String ASK_SUCCESS = "Success";
    private static final String CODE_SUCCESS = "0";

    @ApiModelProperty(value = "响应编码 0：代表成功，其他代表存在错误")
    private String code;

    @ApiModelProperty(value = "响应消息")
    private String message;

    @ApiModelProperty(value = "响应结果")
    private T data;

    public WmsResultRespData(){
    }

    public WmsResultRespData(WmsRespData wmsRespData){
        String ask = wmsRespData.getAsk();
        if(ASK_SUCCESS.equals(ask)){
            this.code = CODE_SUCCESS;
            //wms成功时取message
            this.message = wmsRespData.getMessage();
        }else{
            this.code = wmsRespData.getError().getErrorCode();
            if(StringUtils.isEmpty(this.code))
                this.code = String.valueOf(ErrorCode.INTERNAL_SERVER_ERROR);
            // wms异常时取error中message
            this.message = wmsRespData.getError().getErrorMessage();
            if(StringUtils.isEmpty(this.message))
                this.message = wmsRespData.getMessage();
        }
        this.data = (T) wmsRespData.getData();
    }
}
